package com.demo.jni;

import com.google.protobuf.ByteString;
import com.google.protobuf.InvalidProtocolBufferException;
import com.sixents.algrtk.jni.AlgRtkNativeInterface;
import com.sixents.algrtk.jni.AlgRtkSoResult;
import com.sixents.proto.message.*;

public class RtkDemo {

    public static void main(String[] args) throws InvalidProtocolBufferException {
        // 初始化，程序启动运行一次
        byte[] options = RtkInitOption.newBuilder()
                .setLogFilePath("/srv/www/log/cpplog/")
                .setLogPrintLevel(2)
                .setDataType(RtkDataType.RDT_RTCM)
                .setChipType(RtkChipType.RCT_ST)
                .build()
                .toByteArray();
        AlgRtkNativeInterface algRtkNativeInterface = new AlgRtkNativeInterface();

        algRtkNativeInterface.AlgRtkInit(options);

        // 输入数据
        byte[] rtkInputBytes = RtkInputDatas.newBuilder()
                .setRovDatas(ByteString.copyFrom(new byte[]{})) // 流动站观测数据
                .setRefDatas(ByteString.copyFrom(new byte[]{})) // rtcm数据
                .build().toByteArray();
        AlgRtkSoResult algRtkSoResult = algRtkNativeInterface.AlgRtkDoPos(rtkInputBytes);

        // 返回值
        int code = algRtkSoResult.getCode();
        RtkOutputDatas outputData = RtkOutputDatas.parseFrom(algRtkSoResult.getData());
        for (RtkPosResult result : outputData.getRtkPosResultList()) {
            String rmcData = result.getRmcData();
            String ggaData = result.getGgaData();
        }

        // 程序停止前运行一次
        algRtkNativeInterface.AlgRtkFinal();
    }
}
